package com.qf.base;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qf.service.impl.CategoryServiceImpl;
import com.qf.service.impl.NewServiceImpl;
import com.qf.service.impl.OrderServiceImpl;
import com.qf.service.impl.ProductServiceImpl;
import com.qf.service.impl.UserServiceImpl;

public class BaseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected UserServiceImpl userServiceImpl = new UserServiceImpl();
	protected CategoryServiceImpl categoryServiceImpl = new CategoryServiceImpl();
	protected NewServiceImpl newServiceImpl = new NewServiceImpl();
	protected ProductServiceImpl productServiceImpl = new ProductServiceImpl();
	protected OrderServiceImpl orderServiceImpl = new OrderServiceImpl();
	
	
    public BaseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String action = request.getParameter("action");
		Class<? extends BaseServlet> clz = this.getClass();
		try {
			Method method = clz.getDeclaredMethod(action, HttpServletRequest.class,HttpServletResponse.class);
		    try {
		    	method.setAccessible(true);
				method.invoke(this, request,response);
				
			} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
				
				//TODO
				e.printStackTrace();
					
			}
		} catch (NoSuchMethodException e) {
			
			//TODO
			e.printStackTrace();
				
		} catch (SecurityException e) {
			
			//TODO
			e.printStackTrace();
				
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
